package world.xuewei.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import world.xuewei.dao.ShopNoticeDao;
import world.xuewei.model.entity.ShopNotice;
import world.xuewei.service.ShopNoticeService;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.Date;
import java.util.List;

/**
* @author 陈相州
* @description 针对表【shop_notice】的数据库操作Service实现
* @createDate 2024-11-28 16:51:17
*/
@Service
public class ShopNoticeServiceImpl implements ShopNoticeService{

    @Autowired
    private ShopNoticeDao shopNoticeDao;

    @Override
    public List<ShopNotice> getAllShopNoticeList(Long userId) {
        return shopNoticeDao.getAllShopNoticeList(userId);
    }

    @Override
    public List<ShopNotice> getShopNoticeList(Long merchant_id) {
        // 获取当前商家对应的公告
        List<ShopNotice> shopNoticeList = shopNoticeDao.getShopNoticeList(merchant_id);
        for (ShopNotice shopNotice : shopNoticeList) {
            // 判断当前公告的结束时间是否小于或等于当前时间，小于的话代表已经到了公告结束时间或过了公告结束时间
            if (shopNotice.getEndTime() != null && shopNotice.getEndTime().getTime() <= new Date().getTime()) {
                // 修改公告状态
                shopNoticeDao.setIsStatus(shopNotice.getId());
            }
        }
        return shopNoticeDao.getShopNoticeList(merchant_id);
    }

    // 添加
    @Override
    public int addShopNotice(ShopNotice shopNotice) {
        return shopNoticeDao.addShopNotice(shopNotice);
    }

    // 修改
    @Override
    public int updateShopNotice(ShopNotice shopNotice) {
        return shopNoticeDao.updateShopNotice(shopNotice);
    }

    // 删除
    @Override
    public int deleteShopNotice(Long id) {
        return shopNoticeDao.deleteShopNotice(id);
    }
}




